/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.component.comboBox;

import java.awt.BorderLayout;
import java.io.Serializable;

import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.plaf.ComboBoxUI;
import javax.swing.plaf.basic.ComboPopup;
import javax.swing.plaf.metal.MetalComboBoxUI;
import javax.swing.table.DefaultTableModel;

import com.sun.java.swing.plaf.motif.MotifComboBoxUI;
import com.sun.java.swing.plaf.windows.WindowsComboBoxUI;
/**
 * 进销属性：销售
 */
public class CommodityJComboBoxTableSales extends JComboBox implements Serializable {

	private static final long serialVersionUID = 1L;

	public CommodityJComboBoxTableSales()
			throws UnsupportedOperationException {
	}

	@Override
	public void setSelectedItem(Object anObject) {
		super.setSelectedItem(anObject);
	}

	/**
	 *更新UI
	 */
	@Override
	public void updateUI() {
		ComboBoxUI cui = (ComboBoxUI) UIManager.getUI(this);
		if (cui instanceof MetalComboBoxUI) {
			cui = new MetalDateComboBoxUI();
		} else if (cui instanceof MotifComboBoxUI) {
			cui = new MotifDateComboBoxUI();
		} else {
			cui = new WindowsDateComboBoxUI();
		}
		setUI(cui);
	}

	class MetalDateComboBoxUI extends MetalComboBoxUI {
		protected ComboPopup createPopup() {
			return new CommodityJComboBoxTabelPopupSales(comboBox);
		}
	}

	class WindowsDateComboBoxUI extends WindowsComboBoxUI {
		protected ComboPopup createPopup() {
			return new CommodityJComboBoxTabelPopupSales(comboBox);
		}
	}

	class MotifDateComboBoxUI extends MotifComboBoxUI {
		private static final long serialVersionUID = 1L;

		protected ComboPopup createPopup() {
			return new CommodityJComboBoxTabelPopupSales(comboBox);
		}
	}
	
	public static void main(String args[]){
			JFrame f = new JFrame();
			f.setSize(300,300);
			JTable table = new JTable(5, 10);
			DefaultTableModel tableModel = new DefaultTableModel();
			tableModel.addColumn("商品编号");
			tableModel.addColumn("商品名称");
			tableModel.addColumn("价格");
			tableModel.addColumn("现价");
			tableModel.addColumn("批发价");
			Object[][] objs = new Object[][] { {}, {}, {},{}, {}, {} };
			tableModel.addRow(objs);
			JComboBox editor = new CommodityJComboBoxTableSales();
			editor.setBorder(null);
			table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
			table.setDefaultEditor(Object.class, new DefaultCellEditor(editor));
			JScrollPane sp = new JScrollPane(table);
			f.getContentPane().add(sp, BorderLayout.CENTER);
			// f.setSize(600, 400);
			table.updateUI();
			f.setVisible(true);
	    }
}
